package ltd.trackan.aitextdialogue.model.enumeration;

import java.util.HashMap;
import java.util.Map;

/**
 * @author wxa
 */

public enum LargeScaleModel {
    DEEPSEEK_CHAT("deepseek-chat"),
    DEEPSEEK_REASONER("deepseek-reasoner"),
    QWQ_PLUS("qwq-plus"),
    QWEN_MAX("qwen-max"),
    QWEN_PLUS("qwen-plus"),
    QWEN_TURBO("qwen-turbo"),
    QWEN_LONG("qwen-long"),
    QWEN_OMNI_TURBO("qwen-omni-turbo"),
    QWEN_VL_MAX("qwen-vl-max"),
    QWEN_VL_OCR("qwen-vl-ocr"),
    QWEN_AUDIO_TURBO("qwen-audio-turbo"),
    QWEN_AUDIO_ASR("qwen-audio-asr"),
    QWEN_MATH_PLUS("qwen-math-plus"),
    QWEN_CODER_PLUS("qwen-coder-plus"),
    QWEN_MT_PLUS("qwen-mt-plus");
    
    private final String model;
    
    LargeScaleModel(String model) {
        this.model = model;
    }
    
    public String getModel() {
        return model;
    }
    
    // 判断输入字符串是否匹配枚举字段
    public static boolean isValidModel(String input) {
        if (input == null || input.isEmpty()) {
            return false;
        }
        for (LargeScaleModel model : LargeScaleModel.values()) {
            if (model.getModel().equals(input)) {
                return true;
            }
        }
        return false;
    }
    
    // 根据输入字符串返回对应的 URL
    public static String getEndpoint(String input) {
        if (!isValidModel(input)) {
            throw new IllegalArgumentException("1：大模型名不正确: " + input);
        }
        switch (input) {
            case "deepseek-chat":
            case "deepseek-reasoner":
                return "https://api.deepseek.com/chat/completions";
            case "qwq-plus":
            case "qwen-max":
            case "qwen-plus":
            case "qwen-turbo":
            case "qwen-long":
            case "qwen-omni-turbo":
            case "qwen-vl-max":
            case "qwen-vl-ocr":
            case "qwen-audio-turbo":
            case "qwen-audio-asr":
            case "qwen-math-plus":
            case "qwen-coder-plus":
            case "qwen-mt-plus":
                return "https://dashscope.aliyuncs.com/compatible-mode/v1/chat/completions";
            default:
                throw new IllegalArgumentException("2：大模型名不正确: " + input);
        }
        
        
    }
    
    // 根据输入字符串返回对应的请求头
    public static Map<String, String> getHeaders(String input) {
        if (!isValidModel(input)) {
            throw new IllegalArgumentException("1：大模型名不正确: " + input);
        }
        HashMap<String, String> requestHeaders = new HashMap<>();
        requestHeaders.put("Content-Type", "application/json;charset=UTF-8");
        requestHeaders.put("Accept", "application/json");
        switch (input) {
            case "deepseek-chat":
            case "deepseek-reasoner":
                String deepSeekApiKey = System.getenv("DEEP_SEEK_API_KEY");
                if (deepSeekApiKey == null || deepSeekApiKey.isEmpty()) {
                    throw new RuntimeException("没有DeepSeek的Api");
                }
                requestHeaders.put("Authorization", "Bearer " + deepSeekApiKey);
                break;
            case "qwq-plus":
            case "qwen-max":
            case "qwen-plus":
            case "qwen-turbo":
            case "qwen-long":
            case "qwen-omni-turbo":
            case "qwen-vl-max":
            case "qwen-vl-ocr":
            case "qwen-audio-turbo":
            case "qwen-audio-asr":
            case "qwen-math-plus":
            case "qwen-coder-plus":
            case "qwen-mt-plus":
                String aLiYunApiKey = System.getenv("DASHSCOPE_API_KEY");
                if (aLiYunApiKey == null || aLiYunApiKey.isEmpty()) {
                    throw new RuntimeException("没有阿里云的Api");
                }
                requestHeaders.put("Authorization", "Bearer " + aLiYunApiKey);
                break;
            default:
                throw new IllegalArgumentException("2：大模型名不正确: " + input);
        }
        return requestHeaders;
    }
}